package com.ayu.shortlink.project.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * Caffeine 配置类
 */
@Configuration
public class CacheConfig {
    @Bean
    public Cache<String,Object> caffenineCache(){
        return Caffeine.newBuilder()
                // 写入后15分钟过期
                .expireAfterWrite(15, TimeUnit.MINUTES)
                // 初始化缓存大小
                .initialCapacity(500)
                // 缓存最大的大小
                .maximumSize(1000)
                .build();
    }
}
